package xiangmu.schoolpaper.service.impl.teacher;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xiangmu.schoolpaper.mapper.teacher.TeacherScoreMapper;
import xiangmu.schoolpaper.pojo.DTO.SystemTemplateWeightUpdateItemsDTO;
import xiangmu.schoolpaper.pojo.DTO.TeacherScoreByStudentAccountUpdateDTO;
import xiangmu.schoolpaper.pojo.DTO.TeacherScoreByStudentAccountUpdateItemDTO;
import xiangmu.schoolpaper.service.TeacherScoreService;

import java.util.List;

@Service
public class TeacherScoreServiceImpl implements TeacherScoreService {
    @Autowired
    private TeacherScoreMapper teacherScoreMapper;

//    根据学生的id修改学生详细评分信息
    public Boolean updatePaperScoreByStudentAccount(TeacherScoreByStudentAccountUpdateDTO dto) {
        Integer paperId = dto.getPaperId();
        List<TeacherScoreByStudentAccountUpdateItemDTO> factors = dto.getFactors();

        if (paperId == null || factors == null || factors.isEmpty()) {
            return false;
        }

        for (TeacherScoreByStudentAccountUpdateItemDTO item : factors) {
            Integer rows = teacherScoreMapper.updatePaperScoreByStudentAccount(
                    paperId, item.getFactorId(), item.getScore(), item.getSuggest()
            );
            if (rows == 0) {
                throw new RuntimeException("更新失败：factorId=" + item.getFactorId());
            }
        }

        return true;
    }
}
